package view;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.JButton;

import domain.ISalvable;

public class VSave extends JPanel {

	private static final long serialVersionUID = 1L;
	private JButton bSave = null;
	private JButton bCancel = null;
	ISalvable salvable = null;
	
	/**
	 * This is the default constructor
	 */
	public VSave(ISalvable s) {
		super();
		salvable = s;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		//this.setSize(300, 200);
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		this.add(getBSave(), null);
		this.add(getBCancel(), null);
	}

	/**
	 * This method initializes bSave	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBSave() {
		if (bSave == null) {
			bSave = new JButton();
			bSave.setText("Save");
			bSave.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try {
						salvable.save();
					} catch (Exception e1) {
						salvable.close();
					}
				}
			});
		}
		return bSave;
	}

	/**
	 * This method initializes bCancel	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBCancel() {
		if (bCancel == null) {
			bCancel = new JButton();
			bCancel.setText("Cancel");
			bCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					salvable.close();
				}
			});
		}
		return bCancel;
	}

}
